package com.tsing.cedap.rest.controller;

import com.tsing.cedap.common.annotations.SystemLog;
import com.tsing.cedap.common.utils.ResultUtil;
import com.tsing.cedap.common.vo.PageResult;
import com.tsing.cedap.common.vo.ResultData;
import com.tsing.cedap.rest.service.IOrderService;
import com.tsing.cedap.rest.vo.reqVo.*;
import com.tsing.cedap.rest.vo.respVo.OrderRespVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author TheTsing
 * @create 2022-01-28 9:25
 */
@Api(tags = "订单模块")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @PostMapping("/placeOrder")
    @ApiOperation(value = "下单")
    @SystemLog(description = "下单")
    public ResultData placeOrder(@Validated @RequestBody PlaceOrderReqVo reqVo, HttpServletRequest request) {
        orderService.placeOrder(reqVo, request);
        return ResultUtil.success();
    }

    @PostMapping("/updateTip")
    @ApiOperation(value = "修改打赏金额")
    @SystemLog(description = "修改打赏金额")
    public ResultData updateTip(@Validated @RequestBody UpdateTipReqVo reqVo) {
        orderService.updateTip(reqVo);
        return ResultUtil.success();
    }

    @PostMapping("/cancelOrder")
    @ApiOperation(value = "取消订单")
    @SystemLog(description = "取消订单")
    public ResultData cancelOrder(@Validated @RequestBody CancelOrderReqVo reqVo) {
        orderService.cancelOrder(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/getOrderById")
    @ApiOperation(value = "获取单个订单信息")
    @SystemLog(description = "获取单个订单信息")
    public ResultData<OrderRespVo> getOrderById(@Validated CodeReqVo reqVo) {
        return ResultUtil.success(orderService.getOrderById(reqVo));
    }

    @GetMapping("/orderPage")
    @ApiOperation(value = "订单分页查询")
    @SystemLog(description = "订单分页查询")
    public ResultData<PageResult<OrderRespVo>> orderPage(@Validated OrderPageReqVo reqVo, HttpServletRequest request) {
        return ResultUtil.success(orderService.orderPage(reqVo, request));
    }

    @GetMapping("/riderOrderPage")
    @ApiOperation(value = "骑手的接单列表分页")
    @SystemLog(description = "骑手的接单列表分页")
    public ResultData<PageResult<OrderRespVo>> riderOrderPage(@Validated OrderPageReqVo reqVo, HttpServletRequest request) {
        return ResultUtil.success(orderService.riderOrderPage(reqVo, request));
    }

    @GetMapping("/missedOrdersPage")
    @ApiOperation(value = "可抢单列表分页")
    @SystemLog(description = "可抢单列表分页")
    public ResultData<PageResult<OrderRespVo>> missedOrdersPage(@Validated IdAndPageReqVo reqVo, HttpServletRequest request) {
        return ResultUtil.success(orderService.missedOrdersPage(reqVo, request));
    }

    @PostMapping("/updateRider")
    @ApiOperation(value = "修改订单的骑手")
    @SystemLog(description = "修改订单的骑手")
    public ResultData updateRider(@Validated @RequestBody UpdateRiderReqVo reqVo) {
        orderService.updateRider(reqVo);
        return ResultUtil.success();
    }

    @PostMapping("/riderReceive")
    @ApiOperation(value = "骑手接单")
    @SystemLog(description = "骑手接单")
    public ResultData riderReceive(@Validated @RequestBody RiderReceiveReqVo reqVo) {
        orderService.riderReceive(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/getQr")
    @ApiOperation(value = "客户端生成二维码")
    @SystemLog(description = "客户端生成二维码")
    public ResultData getQr(@Validated CodeReqVo reqVo) {
        return ResultUtil.success(orderService.getQr(reqVo));
    }

    @PostMapping("/verifyQr")
    @ApiOperation(value = "验证二维码，签收")
    @SystemLog(description = "验证二维码，签收")
    public ResultData verifyQr(@Validated @RequestBody CodeReqVo reqVo) {
        orderService.verifyQr(reqVo);
        return ResultUtil.success();
    }

    @PostMapping("/customerPay")
    @ApiOperation(value = "用户使用余额支付订单金额")
    @SystemLog(description = "用户使用余额支付订单金额")
    public ResultData customerPay(@Validated @RequestBody CodeReqVo reqVo) {
        orderService.customerPay(reqVo);
        return ResultUtil.success();
    }

    @PostMapping("/riderPay")
    @ApiOperation(value = "骑手点击的线下支付")
    @SystemLog(description = "骑手点击的线下支付")
    public ResultData riderPay(@Validated @RequestBody CodeReqVo reqVo) {
        orderService.riderPay(reqVo);
        return ResultUtil.success();
    }


}
